import Mock from 'mockjs'

const url = {
  calendar: /\/mock\/calendar/, // 日历数据
}

const statusEnums = [
  { status: 1, text: '上班' },
  { status: 2, text: '远程' },
  { status: 3, text: '休息' },
]

Mock.mock(url.calendar, 'post', (options) => {
  const { year, month } = JSON.parse(options.body)
  const daysInMonth = new Date(year, month, 0).getDate()
  let calendarData = {}

  for (let day = 1; day <= daysInMonth; day++) {
    const dateFormatted = `${year}-${month}-${String(day).padStart(2, '0')}`
    // 从状态枚举数组中随机选择一个状态
    const randomStatus =
      statusEnums[Math.floor(Math.random() * statusEnums.length)]

    calendarData[dateFormatted] = {
      status: randomStatus.status,
      text: randomStatus.text,
    }
  }

  return {
    code: 1,
    data: calendarData,
    msg: '',
  }
})
